package com.example.testcourse;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.media.MediaPlayer;
import android.os.Bundle;
public class AlarmActivity2 extends Activity
{
    MediaPlayer alarmMusic1;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        // 加载指定音乐，并为之创建MediaPlayer对象
        alarmMusic1 = MediaPlayer.create(this, R.raw.a);
        alarmMusic1.setLooping(true);
        // 播放音乐
        alarmMusic1.start();
        // 创建一个对话框
        new AlertDialog.Builder(AlarmActivity2.this).setTitle("闹钟")
                .setMessage("请及时交作业")
                .setPositiveButton("确定", new OnClickListener()
                {
                    @Override
                    public void onClick(DialogInterface dialog, int which)
                    {
                        // 停止音乐
                        alarmMusic1.stop();
                        // 结束该Activity
                        AlarmActivity2.this.finish();
                    }
                }).show();







    }


}

